package com.example.once.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.once.entity.User;
import com.example.once.mapper.UserMapper;
import com.example.once.common.PageQuery;
import com.example.once.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xinTong
 * @since 2023-12-12
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public IPage<Map<String, Object>> select(PageQuery query) {
        LambdaQueryWrapper<User> userLambdaQueryWrapper = Wrappers.lambdaQuery();

        // 查询条件
        if (query.getName() != null){
            userLambdaQueryWrapper.like(User::getName , query.getName());
        }
        if (query.getSex() != null){
            userLambdaQueryWrapper.eq(User::getSex, query.getSex());
        }

        Page<Map<String , Object>> mapPage = new Page<>(query.getPageNum(), query.getPageSize());
        IPage<Map<String , Object>> mapIPage = userMapper.selectMapsPage(mapPage, userLambdaQueryWrapper);

        return mapIPage;

    }
}
